const sha1 = require('sha1');
const config = require('./config');

module.exports = () => {
    return async ctx => {
        const { signature, echostr, timestamp, nonce } = ctx.query;
        const { token } = config;
        const sha1str = sha1([timestamp, nonce, token].join('')); //sha1加密
        if (ctx.method === 'GET') {
            if (sha1str === signature) {
                return ctx.body = echostr;
            }
        } else if (ctx.method === 'POST') {
            // post接受的数据
        }
    }
}